home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / lsort.test < prev    next >
Text File  |  1993-05-07  |  6KB  |  137 lines

  1. # Commands covered:  lsort
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/lsort.test,v 1.3 93/05/07 16:27:30 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. test lsort-1.1 {lsort command} {
  32.     lsort {abdeq ab 1 ac a}
  33. } {1 a ab abdeq ac}
  34. test lsort-1.2 {lsort command} {
  35.     lsort -decreasing {abdeq ab 1 ac a}
  36. } {ac abdeq ab a 1}
  37. test lsort-1.3 {lsort command} {
  38.     lsort -increasing {abdeq ab 1 ac a}
  39. } {1 a ab abdeq ac}
  40. test lsort-1.4 {lsort command} {
  41.     lsort {{one long element}}
  42. } {{one long element}}
  43. test lsort-1.5 {lsort command} {
  44.     lsort {}
  45. } {}
  46. test lsort-1.6 {lsort with characters needing backslashes} {
  47.     lsort {$ \\ [] \{}
  48. } {{$} {[]} \\ \{}
  49.  
  50. test lsort-2.1 {lsort -integer} {
  51.     lsort -integer -inc {1 180 62 040 180 -42 33 0x40}
  52. } {-42 1 040 33 62 0x40 180 180}
  53. test lsort-2.2 {lsort -integer} {
  54.     lsort -int -dec {1 180 62 040 180 -42 33 0x40}
  55. } {180 180 0x40 62 33 040 1 -42}
  56. test lsort-2.3 {lsort -integer} {
  57.     list [catch {lsort -integer {xxx 180.2 62 040 180 -42 33 0x40}} msg] $msg $errorInfo
  58. } {1 {expected integer but got "xxx"} {expected integer but got "xxx"
  59.     (converting list element from string to integer)
  60.     invoked from within
  61. "lsort -integer {xxx 180.2 62 040 180 -42 33 0x40}"}}
  62. test lsort-2.4 {lsort -integer} {
  63.     list [catch {lsort -integer {1 180.2 62 040 180 -42 33 0x40}} msg] $msg $errorInfo
  64. } {1 {expected integer but got "180.2"} {expected integer but got "180.2"
  65.     (converting list element from string to integer)
  66.     invoked from within
  67. "lsort -integer {1 180.2 62 040 180 -42 33 0x40}"}}
  68.  
  69. test lsort-3.1 {lsort -real} {
  70.     lsort -real {1 180.0 62 040 180 -42.7 33}
  71. } {-42.7 1 33 040 62 180 180.0}
  72. test lsort-3.2 {lsort -real} {
  73.     lsort -r -d {1 180.0 62 040 180 -42.7 33}
  74. } {180 180.0 62 040 33 1 -42.7}
  75. test lsort-3.3 {lsort -real} {
  76.     list [catch {lsort -real -inc {xxx 0x40 62 180 -42.7 33}} msg] $msg $errorInfo
  77. } {1 {expected floating-point number but got "xxx"} {expected floating-point number but got "xxx"
  78.     (converting list element from string to real)
  79.     invoked from within
  80. "lsort -real -inc {xxx 0x40 62 180 -42.7 33}"}}
  81. test lsort-3.4 {lsort -real} {
  82.     list [catch {lsort -real -inc {1 0x40 62 180 -42.7 33}} msg] $msg $errorInfo
  83. } {1 {expected floating-point number but got "0x40"} {expected floating-point number but got "0x40"
  84.     (converting list element from string to real)
  85.     invoked from within
  86. "lsort -real -inc {1 0x40 62 180 -42.7 33}"}}
  87.  
  88. proc lsort1 {a b} {
  89.     expr {2*([string match x* $a] - [string match x* $b])
  90.         + [string match *y $a] - [string match *y $b]}
  91. }
  92. proc lsort2 {a b} {
  93.     error "comparison error"
  94. }
  95. proc lsort3 {a b} {
  96.     concat "foobar"
  97. }
  98.  
  99. test lsort-4.1 {lsort -command} {
  100.     lsort -command lsort1 {xxx yyy abc {xx y}}
  101. } {abc yyy xxx {xx y}}
  102. test lsort-4.2 {lsort -command} {
  103.     lsort -command lsort1 -dec {xxx yyy abc {xx y}}
  104. } {{xx y} xxx yyy abc}
  105. test lsort-4.3 {lsort -command} {
  106.     list [catch {lsort -command lsort2 -dec {1 2 3 4}} msg] $msg $errorInfo
  107. } {1 {comparison error} {comparison error
  108.     while executing
  109. "error "comparison error""
  110.     (procedure "lsort2" line 2)
  111.     invoked from within
  112. "lsort2 1 3"
  113.     (user-defined comparison command)
  114.     invoked from within
  115. "lsort -command lsort2 -dec {1 2 3 4}"}}
  116. test lsort-4.4 {lsort -command} {
  117.     list [catch {lsort -command lsort3 -dec {1 2 3 4}} msg] $msg $errorInfo
  118. } {1 {comparison command returned non-numeric result} {comparison command returned non-numeric result
  119.     while executing
  120. "lsort -command lsort3 -dec {1 2 3 4}"}}
  121. test lsort-4.5 {lsort -command} {
  122.     list [catch {lsort -command {xxx yyy xxy abc}} msg] $msg
  123. } {1 {"-command" must be followed by comparison command}}
  124.  
  125. test lsort-5.1 {lsort errors} {
  126.     list [catch lsort msg] $msg
  127. } {1 {wrong # args: should be "lsort ?-ascii? ?-integer? ?-real? ?-increasing? ?-decreasing? ?-command string? list"}}
  128. test lsort-5.2 {lsort errors} {
  129.     list [catch {lsort a b} msg] $msg
  130. } {1 {bad switch "a": must be -ascii, -integer, -real, -increasing -decreasing, or -command}}
  131. test lsort-5.3 {lsort errors} {
  132.     list [catch {lsort "\{"} msg] $msg
  133. } {1 {unmatched open brace in list}}
  134. test lsort-5.4 {lsort errors} {
  135.     list [catch {lsort -in {1 180.0 040 62 180 -42.7 33}} msg] $msg
  136. } {1 {bad switch "-in": must be -ascii, -integer, -real, -increasing -decreasing, or -command}}
  137.